package com.gy.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.gy.dao.ApartmentMapper;
import com.gy.dao.RoomMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gy.domain.Apartment;
import com.gy.domain.Room;

/**
 * ��ȡ����
 * @author Administrator
 *
 */
@Service
@Transactional
public class GetRoomsService {
	
	@Autowired
	private SqlSessionFactory sqlSessionFactory;


	public List<Room> getrooms()
	{

			SqlSession openSession = sqlSessionFactory.openSession();
			RoomMapper roomMapper =  openSession.getMapper(RoomMapper.class);
			List<Room> roomAll = roomMapper.selectAll();
			openSession.close();
			return roomAll;
	}

	/**
	 * 获取所有楼
	 * @return
	 */
	public Map<Integer, Integer> getapartment()
	{
		int i=0;
		SqlSession openSession = sqlSessionFactory.openSession();
		ApartmentMapper apartmentMapper =  openSession.getMapper(ApartmentMapper.class);
		List<Apartment> apartments=apartmentMapper.selectAll();
		List<Integer> a = new ArrayList<Integer>();
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(Apartment ap: apartments)
		{
			a.add(ap.getaId());
			map.put(ap.getaId(), ap.getaFloorn());
			i++;
		}
		openSession.close();
		return	map;
	}
}
